﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Web;
using MarsExplorerWebSite.Model;

namespace MarsExplorerWebSite.Functions
{
    public class getAllWeather : FunctionBase
    {
        private MarsExplorerEntities dbContext;
        public int turnID { get; set; }

        int _moon=0,_solar=0,_long=0;

        public getAllWeather(HttpContext context) : base(context)
        {
            InitializeProperties();
        }

        public override string Execute()
        {
            StringBuilder sb = new StringBuilder();
            for (int i = 1; i <= 30; i++)
            {
                List<GamesEvent> t = (from x in dbContext.GamesEvents where x.GameTurn == i select x).ToList();
                if (t != null)
                {
                    foreach (GamesEvent ge in t)
                    {
                        switch (ge.Route)
                        {
                            case "M":
                                _moon = ge.EventID;
                                break;
                            case "S":
                                _solar = ge.EventID;
                                break;
                            case "L":
                                _long = ge.EventID;
                                break;
                        }
                    }
                }
                sb.Append(_moon.ToString() + ";" + _solar.ToString() + ";" + _long.ToString()+"\r\n");
                _moon = 0;
                _solar = 0;
                _long = 0;
            }
           
            return sb.ToString();
           

          
        }

        public override void InitializeProperties()
        {
            try
            {
                turnID = Convert.ToInt32(Parameters["turnid"]);
                dbContext = new MarsExplorerEntities();
            }
            catch (Exception e)
            {
                string message = "";
                #if DEBUG
                message += " : " + e.ToString();
                #endif
            }
        }
    }
}